// (JSDoc Quick Reference: http://en.wikipedia.org/wiki/JSDoc)

// Interface
interface IHostBridge {
    /** Returns the current working directory for the host app. */
    getCurrentDir(): string;

    /** Returns true if 'host' in the global scope represents the DreamSpace Studio .NET environment. */
    isDreamSpaceStudio(): boolean;

    /** Returns true if 'host' in the global scope represents the DreamSpace Server .NET environment. */
    isDreamSpaceServer(): boolean;

    /** Returns true if 'host' in the global scope represents a basic web navigator/browser application (no DreamSpace specific host bridge is available). */
    isWebNavigator(): boolean;

    /** Sets the host window title, if applicable. */
    setTitle(title: string);

    /** Gets the host window title, if applicable. */
    getTitle(): string;

    /** Returns true if the host is running in debug mode. */
    isDebugMode(): boolean;
}

declare var host: IHostBridge;

// ... if there's no DOM, then the required minimal DOM informational parts need to be simulated ...

if (typeof window == "undefined")
    window = <Window>this;

if (typeof document == "undefined")
    document = <Document>{
        title: "",
        location: {
            href: ""
        },
        getElementById: (elementId: string): HTMLElement => {
            return null;
        }
    };

/** The "fake" browser host object is only used when there is no .NET host available.
* In this case, the environment is running as a simple web application.
*/
class __NonDreamSpaceHost__ implements IHostBridge {

    constructor() { }

    getCurrentDir(): string { return document.location.href; }

    isDreamSpaceStudio(): boolean { return false; }
    isDreamSpaceServer(): boolean { return false; }
    isWebNavigator(): boolean { return !this.isDreamSpaceStudio() && !this.isDreamSpaceServer(); }

    setTitle(title: string) { document.title = title; }
    getTitle(): string { return document.title; }

    isDebugMode(): boolean { return false; }
}

